<template>
	<gui-page ref="guiPage" :customHeader="true">
		<template v-slot:gHeader>
			<nav-bar-custom left-icon="left" :title="$t('navigationBar.facilityInformation')"></nav-bar-custom>
		</template>
		<template v-slot:gBody>
            <form class="form">
				<view class="uni-form-item">
					<view class="title" style="width:300rpx;">{{$t('setting.equipmentNumber')}}：</view>
					<input disabled class="uni-input" v-model="data.code" name="oldPassword" :placeholder="$t('setting.equipmentNumber')" />
				</view>
                <view class="uni-form-item">
					<view class="title" style="width:300rpx;">{{$t('setting.equipmentMAC')}}：</view>
					<input disabled class="uni-input" v-model="data.mac" :placeholder="$t('setting.equipmentMAC')" />
				</view>
                <view class="uni-form-item">
					<view class="title" style="width:300rpx;">{{$t('setting.ipLocation')}}：</view>
					<input disabled class="uni-input" v-model="data.ip" :placeholder="$t('setting.ipLocation')" />
				</view>
				<view class="page-bottom-boxtwo">
					<button class="button" type="primary" @click="handel">{{$t("popup.confirm")}}</button>
				</view>
			</form>
		</template>
	</gui-page>
</template>

<script setup>
    import {
		reLaunch
	} from '@/utils/routerSkip.js'
    import { navigateBack } from '@/utils/routerSkip.js';
	import {
		reactive,
		onMounted
	} from 'vue';
	onMounted(()=>{
       data.ip = getDeviceIp()
       data.mac = getDeviceMac()
       data.code = getDeviveCode()
	})
	let data = reactive({
        ip:'',
        mac:'',
        code:''
	})
    const handel = () => {
        navigateBack()
    }
    const getDeviceIp = ()=> {  
        var deviceIp = ''
        try {
            if(plus.os.name=="Android"){  
                var Context = plus.android.importClass("android.content.Context");  
                var wifiManager =plus.android.runtimeMainActivity().getSystemService(Context.WIFI_SERVICE);  
                var wifiInfo = plus.android.invoke(wifiManager, "getConnectionInfo");  
                var ipAddress = plus.android.invoke(wifiInfo, "getIpAddress");  
                deviceIp = '';  
                if (ipAddress != 0) {  
                    deviceIp = ((ipAddress & 0xff) + "." + (ipAddress >> 8 & 0xff) + "." + (ipAddress >> 16 & 0xff) + "." + (ipAddress >> 24 & 0xff));  
                }  
            }   
            return deviceIp;  
            
        } catch (error) {
            return ''; 
        }
    }
    const getDeviceMac = ()=> { 
        var deviceMac = ''
        try {
            var net = plus.android.importClass("java.net.NetworkInterface")  
            var wl0 = net.getByName('wlan0')  
            var macByte = wl0.getHardwareAddress()  
            deviceMac = ''  
            for (var i = 0; i < macByte.length; i++) {  
                var tmp = "";  
                var num = macByte[i];  
                if (num < 0) {  
                    tmp = (255 + num + 1).toString(16);  
                } else {  
                    tmp = num.toString(16);  
                }  
                if (tmp.length == 1) {  
                    tmp = "0" + tmp;  
                }  
                deviceMac += tmp;  
            } 
            return deviceMac
            
        } catch (error) {
            return ''
        }
    }
    const getDeviveCode = ()=>{
        try {
            var Build = plus.android.importClass("android.os.Build");
                var Manifest = plus.android.importClass("android.Manifest");
                var MainActivity = plus.android.runtimeMainActivity();
                var SystemProperties = plus.android.importClass("android.os.SystemProperties")
                var serial = ''				
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { //9.0+
                var ArrPermissions = [
                    Manifest.permission.READ_PHONE_STATE,
                ];
                function PermissionCheck(permission) {
                    if (Build.VERSION.SDK_INT >= 23) {
                        if (MainActivity.checkSelfPermission(permission) == -1) {
                            return false;
                        }
                    }
                    return true;
                }
                            
                function PermissionChecks(Arr) {
                    var HasPermission = true;
                    for (var index in Arr) {
                        var permission = Arr[index];
                            //如果此处没有权限,则是用户拒绝了
                        if (!PermissionCheck(permission)) {
                            HasPermission = false;
                            break;
                        }
                    }
                    return HasPermission;
                }
                function PermissionRequest(Arr) {
                    var REQUEST_CODE_CONTACT = 101;
                    if (Build.VERSION.SDK_INT >= 23) {
                        MainActivity.requestPermissions(Arr, REQUEST_CODE_CONTACT);
                    }
                }
                //如果没有权限，则申请权限
                if (!PermissionChecks(ArrPermissions)) {
                    PermissionRequest(ArrPermissions);//此处申请权限，会弹出一个让你授权可获取设备号信息权限框
                } else { //如果拥有权限
                    serial = Build.getSerial()
                }
            } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) { //8.0+
                if (Build.SERIAL) {
                    serial = Build.SERIAL;
                }
            } else {
                if (SystemProperties.get('ro.serialno')) {
                    serial = SystemProperties.get('ro.serialno')
                }
            }
            return serial
        } catch (error) {
            return ''
        }
    }
</script>

<style lang="less">
.form{
    margin: 20rpx;
    // background: #fff;
    border-radius: 10rpx;
    .uni-form-item{
        display: flex;
        align-items: center;
        box-sizing: border-box;
        padding: 24rpx;
        border: 1rpx solid #A5A5A5;
        background: #fff;
        box-shadow: 0rpx 0rpx 8rpx 0 #A5A5A5;
        border-radius: 10rpx;
        overflow: hidden;
        margin-bottom: 24rpx;
        font-size: 26rpx;
        .title{
            color: #333;
            width: 170rpx;
        }
        .uni-input{
            flex: 1;
            color: #333;
            font-size: 26rpx;
        }
    }
    .checkbox{
        margin-top: 30rpx;
        display: flex;
        color: #fff;
        align-items: center;
        justify-content: flex-end;
    }
}
.button{
    background-color: rgb(55, 136, 108) !important;
    width: 100%;
}

</style>
